package com.yanq.liancar.fragment;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.flyco.tablayout.SlidingTabLayout;
import com.gyf.barlibrary.ImmersionBar;
import com.vondear.rxtool.RxActivityTool;
import com.yanq.liancar.R;
import com.yanq.liancar.activity.FindMessageActivity;
import com.yanq.liancar.base.BaseLYFragment;
import com.yanq.liancar.base.BaseLazyFragment;
import com.yanq.liancar.util.LogUtils;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * A simple {@link Fragment} subclass.
 */
public class FindFragment extends BaseLazyFragment {
    @BindView(R.id.img_message)
    ImageView imgMessage;
    @BindView(R.id.ll_top)
    RelativeLayout llTop;
    @BindView(R.id.tab_layout)
    SlidingTabLayout mTabLayout;
    @BindView(R.id.viewpage)
    ViewPager mViewPager;
    Unbinder unbinder;
    private ArrayList<Fragment> mFragments = new ArrayList<>();
    private final String[] mTitles = {
            "精选", "经济", "金融"
            , "互联网", "美妆", "生活"
    };
    private MyPagerAdapter mAdapter;


    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        for (int i = 0; i < mTitles.length; i++) {
            mFragments.add(SimpleCardFragment.getInstance(i));
        }

        mAdapter = new MyPagerAdapter(getChildFragmentManager());
        mViewPager.setAdapter(mAdapter);
        mTabLayout.setViewPager(mViewPager);
        LogUtils.e("111111111111","FindFragment======onViewCreated");
    }

    @Override
    public void onResume() {
        super.onResume();
        LogUtils.e("111111111111","FindFragment======onResume");
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(mActivity).statusBarDarkFont(true).init();
    }

    @OnClick(R.id.img_message)
    public void onViewClicked() {
        RxActivityTool.skipActivity(mActivity, FindMessageActivity.class);
    }

    @Override
    protected int setLayoutId() {
        return R.layout.fragment_cfind;
    }

//    @Override
//    protected void onCreateViewLazy(Bundle savedInstanceState) {
//        super.onCreateViewLazy(savedInstanceState);
//        setContentView(R.layout.fragment_cfind);
//        ImmersionBar.with(mActivity).statusBarColor(R.color.white).statusBarDarkFont(true).init();
//
//        for (int i = 0; i < mTitles.length; i++) {
//            mFragments.add(SimpleCardFragment.getInstance(i));
//        }
//
//        mAdapter = new MyPagerAdapter(getChildFragmentManager());
//        mViewPager.setAdapter(mAdapter);
//        mTabLayout.setViewPager(mViewPager);
//        LogUtils.e("111111111111","FindFragment======onViewCreated");
//    }
//
//    @Override
//    protected void onResumeLazy() {
//        super.onResumeLazy();
//        LogUtils.e("111111111111","FindFragment======onResume");
//    }

    private class MyPagerAdapter extends FragmentPagerAdapter {
        public MyPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return mFragments.size();
        }

        @Override
        public CharSequence getPageTitle(int position) {
            return mTitles[position];
        }

        @Override
        public Fragment getItem(int position) {
            return mFragments.get(position);
        }
    }

}
